//
//  SEGIntegratedServicesListViewModel.m
//  AFNetworking
//
//  Created by 梁学彰 on 2020/11/26.
//

#import "SEGIntegratedServicesListViewModel.h"
#import "SEGIntegratedServicesManager.h"

@implementation SEGIntegratedServicesListViewModel

- (RACSignal *)requestData {
    @weakify(self);
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        @strongify(self);
        
        [SEGIntegratedServicesManager requestIntegratedServiceListWithFinished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
            if (!isSuccessed) {
                [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:errorMessage}]];
                return;
            }
            NSMutableArray<SEGIntegratedServicesListModel *> *tempArray = [NSMutableArray array];
            for (NSDictionary *subDic in result[@"data"]) {
                SEGIntegratedServicesListModel *model = [SEGIntegratedServicesListModel yy_modelWithDictionary:subDic];
                [tempArray addObject:model];
            }
            self.dataSource = [tempArray copy];
            [subscriber sendCompleted];
        }];
        
        return nil;
    }];
    return signal;
}

@end
